﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace Miao.Stand
{
    public class StandAbilityTracker : IExposable
    {
        public StandPawn stand;
        public StandAbilityTracker(StandPawn standPawn)
        {
            stand = standPawn;
        }


        public List<StandAbility> standAbilities = new List<StandAbility>();

        public IEnumerable<Gizmo> GetGizmos()
        {
            return standAbilities.Select(v => v.DrawGizmo());
        }

        public T GetAbilitie<T>() where T: StandAbility
        {
            for(int i=0;i< standAbilities.Count;i++)
            {
                if(standAbilities[i] is T)
                {
                    return standAbilities[i] as T;
                }
            }
            return null;
        }

        public void Tick()
        {
            int count = standAbilities.Count;
            for (int i=0;i< count; i++)
            {
                standAbilities[i].Tick();
            }
        }


        public void ExposeData()
        {
            Scribe_Collections.Look(ref standAbilities, "standAbilities", LookMode.Deep, stand);

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                standAbilities.RemoveAll((StandAbility sa) => sa.def == null);
            }
        }
    }
}
